import java.util.Scanner;

public class Test {

    /*
    * 3 的幂
    * */
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while(scan.hasNextInt()){
            int n = scan.nextInt();
            System.out.println(isPowerOfThree(n));
        }
    }

    public static boolean isPowerOfThree(int n) {
        if(n <= 0){
            return false;
        }
        return dfs(n);
    }

    private static boolean dfs(int n) {
        if(n == 1) return true;
        if(n % 3 != 0) return false;
        return dfs(n / 3);
    }
}
